package com.du.web.sample.controller;

import com.du.web.sample.model.ResBean;
import com.du.web.sample.util.water.WaterMakeParam;
import com.du.web.sample.util.water.WaterMakeUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @desc:
 * @author: shuangdu
 * @date: 2021/9/14
 * @since: 1.8
 */
@RestController
@RequestMapping(path = "water")
@Slf4j
@RequiredArgsConstructor
public class WaterMakeController {

    @PostMapping(path = "make")
    public ResBean waterMake(@RequestParam(value = "file") MultipartFile file, HttpServletResponse response) {
        try {
            WaterMakeParam waterMakeParam = new WaterMakeParam()
                    .setFileInputStream(file.getInputStream())
                    .setOutputStream(response.getOutputStream())
//                    .setWaterContent("shuangdu@iflytek.com")
                    .setWaterContent("内部专用，禁止外传")
                    .setFileName(file.getOriginalFilename())
                    .setPicFormatName(WaterMakeParam.PicFormatName.JPG);
            WaterMakeUtil.make(waterMakeParam);
            // 返回
        } catch (IOException e) {
            e.printStackTrace();
            return ResBean.error(e.getMessage());
        }

        return ResBean.ok();
    }

}
